package dale.web.english.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import dale.web.common.model.*;
import dale.web.english.model.English;
import dale.web.english.service.EnglishService;

@Controller
@RequestMapping("/english")
public class EnglishGetController {

	@Autowired
	private EnglishService service;
	
	@RequestMapping(value="/", method=RequestMethod.GET) 
	public String index() {
		return "redirect:/english/search";
	}
	
	@RequestMapping(value="/search", method=RequestMethod.GET)
	public PagedList<English> search(@ModelAttribute Condition<English> condition) {
		return service.search(condition);
	}

	@RequestMapping(value="/detail", method=RequestMethod.GET)
	public English detail(@RequestParam Integer no) {
		return service.detail(no);
	}

	@RequestMapping(value="/remove", method=RequestMethod.GET)
	public String remove(@RequestParam Integer no, RedirectAttributes redirectAttributes) {
		service.remove(no);
		redirectAttributes.addFlashAttribute("msg", "Successfully processed.");
		return "redirect:/english/search";
	}

}
